package com.ruoyi.car.controller.parts;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.car.pojo.TbPartMotorInformation;
import com.ruoyi.car.service.parts.ITbPartMotorInformationService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;


@Controller
@RequestMapping("/parts/motorInformation")
public class TbPartMotorInformationController extends BaseController
{
    private String prefix = "parts/motorInformation";

    @Autowired
    private ITbPartMotorInformationService tbPartMotorInformationService;

    @RequiresPermissions("parts:motorInformation:view")
    @GetMapping()
    public String motorInformation()
    {
        return prefix + "/motorInformation";
    }

    @RequiresPermissions("parts:motorInformation:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbPartMotorInformation tbPartMotorInformation)
    {
        startPage();
        List<TbPartMotorInformation> list = tbPartMotorInformationService.selectTbPartMotorInformationList(tbPartMotorInformation);
        return getDataTable(list);
    }


    @RequiresPermissions("parts:motorInformation:export")
    @Log(title = "驱动电机信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbPartMotorInformation tbPartMotorInformation)
    {
        List<TbPartMotorInformation> list = tbPartMotorInformationService.selectTbPartMotorInformationList(tbPartMotorInformation);
        ExcelUtil<TbPartMotorInformation> util = new ExcelUtil<TbPartMotorInformation>(TbPartMotorInformation.class);
        return util.exportExcel(list, "motorInformation");
    }

    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }


    @RequiresPermissions("parts:motorInformation:add")
    @Log(title = "驱动电机信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbPartMotorInformation tbPartMotorInformation)
    {
        return toAjax(tbPartMotorInformationService.insertTbPartMotorInformation(tbPartMotorInformation));
    }


    @GetMapping("/edit/{driveId}")
    public String edit(@PathVariable("driveId") Long driveId, ModelMap mmap)
    {
        TbPartMotorInformation tbPartMotorInformation = tbPartMotorInformationService.selectTbPartMotorInformationById(driveId);
        mmap.put("tbPartMotorInformation", tbPartMotorInformation);
        return prefix + "/edit";
    }


    @RequiresPermissions("parts:motorInformation:edit")
    @Log(title = "驱动电机信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbPartMotorInformation tbPartMotorInformation)
    {
        return toAjax(tbPartMotorInformationService.updateTbPartMotorInformation(tbPartMotorInformation));
    }


    @RequiresPermissions("parts:motorInformation:remove")
    @Log(title = "驱动电机信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbPartMotorInformationService.deleteTbPartMotorInformationByIds(ids));
    }
}
